<?php
/**
 * Created by PhpStorm.
 * User: QWZX
 * Date: 2020/1/6
 * Time: 15:53
 */

namespace App\Http\Controllers;


use Illuminate\Http\Request;

class Dulog
{
    private $logpath='';

    function index(Request $request){
        $this->logpath=app_path().'/../storage/logs';
        $dir=$request->get('dir');
        if(empty($dir)) {
            $dir=$this->logpath;
        }

        if(is_file($dir)) {
            $file_path = $dir;
            if (file_exists($file_path)) {
                $str = file_get_contents($file_path);//将整个文件内容读入到一个字符串中
//                    $str = str_replace("\r\n","<br />",$str);
                return "<xmp>" . $str . "</xmp>";

            }
        }
        $cc=scandir($dir);
        $p='';
        foreach($cc as $value){
            $p.= '<a href="/Dulog?dir='.$dir.urlencode('/').$value.'">'.$value.'</a><br/>';
        }
        return  $p;
    }


}